package br.infnet.projetoarquiteturajava.ejb;

import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.inject.Named;

import br.infnet.projetoarquiteturajava.dao.CepDao;
import br.infnet.projetoarquiteturajava.model.Endereco;
import br.infnet.projetoarquiteturajava.ws.dto.AddressDTO;

/**
 * Session Bean implementation class CEPServiceLocalBean
 */
@Stateless
@Named
@LocalBean
public class CEPServiceLocalBean implements ICEPServiceLocal{

	@EJB
	private CepDao dao;
	
    /**
     * Default constructor. 
     */
    public CEPServiceLocalBean() {
        // TODO Auto-generated constructor stub
    }

	@Override
	public AddressDTO getAddressbyCEP(String cep) {
		
		Endereco model = dao.findByCep(cep);
		
		AddressDTO dto = ModeltoDTO(model);
		
		return dto;
	}
	
	
	private Endereco DTOtoModel (AddressDTO dto) {
		Endereco model = new Endereco();
		
		model.setCep(dto.getCep());
		model.setCidade(dto.getCidade());
		model.setEstado(dto.getEstado());
		model.setLatitude(dto.getLatitude());
		model.setLogradouro(dto.getLogradouro());
		model.setLongitude(dto.getLongitude());
	
		return model;
	}
	
	private AddressDTO ModeltoDTO (Endereco model) {
		AddressDTO dto = new AddressDTO();

		dto.setCep(model.getCep());
		dto.setCidade(model.getCidade());
		dto.setEstado(model.getEstado());
		dto.setLatitude(model.getLatitude());
		dto.setLogradouro(model.getLogradouro());
		dto.setLongitude(model.getLongitude());

		
		return dto;
	}
	
	
	

}
